/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SupplierFrame.java
 *
 * Created on 26 Des 12, 21:46:50
 */
package com.ivanbiz.gui;

import com.ivanbiz.dao.SupplierDAO;
import com.ivanbiz.dao.impl.SupplierDAOImpl;
import com.ivanbiz.helper.GlobalConstant;
import com.ivanbiz.helper.RandomList;
import com.ivanbiz.helper.ServiceHelper;
import com.ivanbiz.helper.UserSession;
import com.ivanbiz.model.Supplier;
import com.ivanbiz.model.User;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Administrator
 */
public class SupplierFrame extends javax.swing.JInternalFrame {

    SupplierDAO supplierDAO = new SupplierDAOImpl();
    List<Supplier> listSupplier = new ArrayList<Supplier>();
    RandomList randomList = new RandomList();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ddMMyy");
    Date date = new Date();
    ServiceHelper serviceHelper = new ServiceHelper();
    User user = UserSession.getUser();

    /** Creates new form SupplierFrame */
    public SupplierFrame() {
        this.setVisible(true);
        initComponents();
        updateData();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        textKode = new javax.swing.JTextField();
        textName = new javax.swing.JTextField();
        textAlamat = new javax.swing.JTextField();
        textFax = new javax.swing.JTextField();
        textTelp = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableData = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        comboSearch = new javax.swing.JComboBox();
        textSearch = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        buttonDelete1 = new javax.swing.JButton();
        buttonUpdate1 = new javax.swing.JButton();
        buttonReset1 = new javax.swing.JButton();
        buttonSave1 = new javax.swing.JButton();

        setClosable(true);
        setTitle("Supplier");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Input", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel1.setText("Kode");

        jLabel2.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel2.setText("Nama");

        textKode.setFont(new java.awt.Font("Monospaced", 1, 14));

        textName.setFont(new java.awt.Font("Monospaced", 1, 14));

        textAlamat.setFont(new java.awt.Font("Monospaced", 1, 14));

        textFax.setFont(new java.awt.Font("Monospaced", 1, 14));

        textTelp.setFont(new java.awt.Font("Monospaced", 1, 14));

        jLabel3.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel3.setText("Alamat");

        jLabel4.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel4.setText("Telp");

        jLabel5.setFont(new java.awt.Font("Monospaced", 1, 14));
        jLabel5.setText("Fax");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textKode, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addComponent(textAlamat, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addComponent(textName, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addComponent(textTelp, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                    .addComponent(textFax, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textKode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(textName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(textAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textTelp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(textFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5)))
                    .addComponent(jLabel3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tabel Data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        tableData.setAutoCreateRowSorter(true);
        tableData.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        tableData.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tableData.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableDataMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tableData);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Search"));

        comboSearch.setFont(new java.awt.Font("Monospaced", 1, 14));

        textSearch.setFont(new java.awt.Font("Monospaced", 1, 14));
        textSearch.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                textSearchKeyReleased(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(comboSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Button", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Monospaced", 0, 11))); // NOI18N

        buttonDelete1.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        buttonDelete1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/delete.jpg"))); // NOI18N
        buttonDelete1.setText("Hapus");
        buttonDelete1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonDelete1ActionPerformed(evt);
            }
        });

        buttonUpdate1.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        buttonUpdate1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/Edit.jpg"))); // NOI18N
        buttonUpdate1.setText("Edit");
        buttonUpdate1.setPreferredSize(new java.awt.Dimension(70, 23));
        buttonUpdate1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonUpdate1ActionPerformed(evt);
            }
        });

        buttonReset1.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        buttonReset1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/Reset.jpg"))); // NOI18N
        buttonReset1.setText("Reset");
        buttonReset1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonReset1ActionPerformed(evt);
            }
        });

        buttonSave1.setFont(new java.awt.Font("Monospaced", 1, 14)); // NOI18N
        buttonSave1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/ivanbiz/gui/icon/save.jpg"))); // NOI18N
        buttonSave1.setText("Simpan");
        buttonSave1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSave1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(buttonSave1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonUpdate1, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonDelete1, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonReset1, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonReset1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonDelete1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonUpdate1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buttonSave1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void textSearchKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textSearchKeyReleased
        try {
            listSupplier = supplierDAO.getDataByLike(Supplier.class, (String) comboSearch.getSelectedItem(), textSearch.getText());
            updateTable();
        } catch (Exception ex) {
            Logger.getLogger(SupplierFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_textSearchKeyReleased

    private void buttonDelete1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonDelete1ActionPerformed
        int response = JOptionPane.showConfirmDialog(null, GlobalConstant.PROCCESS, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            try {
                Supplier supplier = (Supplier) listSupplier.get(tableData.getSelectedRow());
                supplierDAO.delete(supplier);
                JOptionPane.showMessageDialog(this, GlobalConstant.MSG_DELETE);
                updateData();
            } catch (Exception ex) {
                Logger.getLogger(SupplierFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

}//GEN-LAST:event_buttonDelete1ActionPerformed

    private void buttonUpdate1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonUpdate1ActionPerformed
        int response = JOptionPane.showConfirmDialog(null, GlobalConstant.PROCCESS, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            try {
                Supplier supplier = (Supplier) listSupplier.get(tableData.getSelectedRow());
                supplier.setKode(textKode.getText());
                supplier.setNama(textName.getText());
                supplier.setAlamat(textAlamat.getText());
                supplier.setTelp(textTelp.getText());
                supplier.setFax(textFax.getText());
                supplier.setUpdatedBy(user.getUserName());
                supplier.setUpdatedDate(new Date());
                supplierDAO.update(supplier);
                JOptionPane.showMessageDialog(this, GlobalConstant.MSG_UPDATE);
                updateData();
            } catch (Exception ex) {
                Logger.getLogger(SupplierFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}//GEN-LAST:event_buttonUpdate1ActionPerformed

    private void buttonReset1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonReset1ActionPerformed
        updateData();
}//GEN-LAST:event_buttonReset1ActionPerformed

    private void buttonSave1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSave1ActionPerformed
        int response = JOptionPane.showConfirmDialog(null, GlobalConstant.PROCCESS, GlobalConstant.CONFIRM, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (response == JOptionPane.YES_OPTION) {
            try {
                Supplier supplier = new Supplier();
                supplier.setKode(textKode.getText());
                supplier.setNama(textName.getText());
                supplier.setAlamat(textAlamat.getText());
                supplier.setTelp(textTelp.getText());
                supplier.setFax(textFax.getText());
                supplier.setCreatedBy(user.getUserName());
                supplier.setCreatedDate(new Date());
                supplierDAO.save(supplier);
                JOptionPane.showMessageDialog(this, GlobalConstant.MSG_SAVE);
                updateData();
            } catch (Exception ex) {
                Logger.getLogger(SupplierFrame.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}//GEN-LAST:event_buttonSave1ActionPerformed

    private void tableDataMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableDataMouseClicked
        Supplier supplier = (Supplier) listSupplier.get(tableData.getSelectedRow());
        textKode.setText(supplier.getKode());
        textName.setText(supplier.getNama());
        textAlamat.setText(supplier.getAlamat());
        textTelp.setText(supplier.getTelp());
        textFax.setText(supplier.getFax());
    }//GEN-LAST:event_tableDataMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonDelete1;
    private javax.swing.JButton buttonReset1;
    private javax.swing.JButton buttonSave1;
    private javax.swing.JButton buttonUpdate1;
    private javax.swing.JComboBox comboSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tableData;
    private javax.swing.JTextField textAlamat;
    private javax.swing.JTextField textFax;
    private javax.swing.JTextField textKode;
    private javax.swing.JTextField textName;
    private javax.swing.JTextField textSearch;
    private javax.swing.JTextField textTelp;
    // End of variables declaration//GEN-END:variables

    private void updateData() {
        try {
            clearData();
            listSupplier = supplierDAO.getAll(Supplier.class);
            updateTable();
            updateCombo();
            textKode.setText("K" + simpleDateFormat.format(date) + randomList.getGeneratePassword());
        } catch (Exception ex) {
            Logger.getLogger(SupplierFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void clearData() {
        textKode.setText(GlobalConstant.EMPTY_STRING);
        textName.setText(GlobalConstant.EMPTY_STRING);
        textAlamat.setText(GlobalConstant.EMPTY_STRING);
        textTelp.setText(GlobalConstant.EMPTY_STRING);
        textSearch.setText(GlobalConstant.EMPTY_STRING);
    }

    private void updateTable() {
        String[] judul = {GlobalConstant.NO, jLabel1.getText(), jLabel2.getText(), jLabel3.getText(), jLabel4.getText(), jLabel5.getText()};
        Object[][] isi = new Object[listSupplier.size()][6];
        int x = 0;
        int no = 0;
        for (Supplier supplier : listSupplier) {
            isi[x][0] = no += 1;
            isi[x][1] = supplier.getKode();
            isi[x][2] = supplier.getNama();
            isi[x][3] = supplier.getAlamat();
            isi[x][4] = supplier.getTelp();
            isi[x][5] = supplier.getFax();
            x++;
        }
        tableData.setModel(new DefaultTableModel(isi, judul) {

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
        });

        TableColumn column0 = tableData.getColumnModel().getColumn(0);
        column0.setPreferredWidth(75);
        column0.setMaxWidth(75);
        TableColumn column1 = tableData.getColumnModel().getColumn(1);
        column1.setPreferredWidth(150);
        column1.setMaxWidth(150);
        TableColumn column4 = tableData.getColumnModel().getColumn(4);
        column4.setPreferredWidth(150);
        column4.setMaxWidth(150);
        TableColumn column5 = tableData.getColumnModel().getColumn(5);
        column5.setPreferredWidth(150);
        column5.setMaxWidth(150);
    }

    private void updateCombo() {
        Object[] dataClass = serviceHelper.getPropertyClass(Supplier.class);
        Object[] dataSearch = new Object[2];
        dataSearch[0] = dataClass[1];
        dataSearch[1] = dataClass[2];
        comboSearch.setModel(new DefaultComboBoxModel(dataSearch));
    }
}
